import { createApp, provide } from "vue";
import { createPinia } from "pinia";
import ElementPlus, { ElIcon, type IconInstance } from "element-plus";
import * as ElIcom from "@element-plus/icons-vue";
import "element-plus/dist/index.css";

import App from "./App.vue";
import router from "./router";

import "./assets/main.css";

import axios from "@/server/server";
import Mitt from "mitt";

const app = createApp(App);
const mitt = Mitt();
// 第一种引入icon方法
for (let iconName in ElIcom) {
  app.component(iconName,ElIcom[iconName as keyof typeof ElIcom]);
}

// 第二种引入icon方法
// Object.keys(ElIcom).forEach((key:any) => {
//   app.component(key,ElIcom[key as keyof typeof ElIcom]);
// });

declare module "vue" {
  export interface ComponentCustomProperties {
    $Bus: typeof mitt;
  }
}

app.config.globalProperties.$http = axios;
app.config.globalProperties.$Bus = mitt;

//  路由全局后置守卫  页面跳转回到页面顶部
router.afterEach((to, from, next) => {
  window.scrollTo(0, 0);
});

app.use(ElementPlus);
app.use(createPinia());
app.use(router);

app.mount("#app");
